package com.logical.test;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * @AUTHOR WANLI_WANG
 * @DATE 2022/6/1
 */
public class TwoNumAdd {

    public static void main(String[] args) {
        int nums[] = {1, 2, 3, 4, 5};
        int target = 3;
        int[] ints = Two.twoAdd(nums, target);

        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i] + "->");
        }
    }

}

class Two {

    /**
     * 两数之和
     *
     * @param nums
     * @param target
     * @return
     */
    public static int[] twoAdd(int[] nums, int target) {
        Stack<Integer> stack = new Stack<>();
        int pivot;

        for (int i = 0; i < nums.length - 1; i++) {
            stack.push(i);
            pivot = nums[i];
            for (int j = i + 1; j < nums.length; j++) {
                int result = addNum(pivot, nums[j]);
                if (result == target) {
                    stack.push(j);
                    break;
                }
            }
            if (stack.size() == 2) {
                break;
            } else {
                stack.pop();
            }
        }
        int[] ints = new int[2];
        for (int i = ints.length - 1; i >= 0; i--) {
            ints[i] = stack.pop();
        }
        return ints;
    }

    public static int addNum(int num1, int num2) {
        return num1 + num2;
    }
}